<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk" %>
<f:view>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>
            <h:outputText value="Goodwill - Сборка заказа" rendered="#{StorekeeperOrderBean.isBuildMode}"/>
            <h:outputText value="Goodwill - Выдача заказа" rendered="#{StorekeeperOrderBean.isOutMode}"/>
        </title>
        <link rel="stylesheet" href="resources/css/main.css"/>
        <link rel="stylesheet" href="resources/css/stylesheet.css"/>
        <link rel="stylesheet" href="resources/css/clients.css"/>
        <style type="text/css">
            .preformatted {
                white-space: pre-wrap;
            }
        </style>

    </head>
    <body>
    <f:verbatim>
        <script type="text/javascript">
            function openPrintPage() {
                window.open("sk3", "Печать", "width=800,height=600,resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no");
            }
        </script>
    </f:verbatim>

    <a4j:form prependId="false" id="jsForm">
        <a4j:jsFunction name="orderNotEditable" ajaxSingle="true"  limitToList="true" action="#{StorekeeperOrderBean.orderPrint}"/>
    </a4j:form>
    <jsp:include page="parts/version.jsp"/>

    <rich:separator/>

    <h:panelGrid columns="2" cellpadding="5" cellspacing="5">
        <h:form>
            <a4j:commandButton value="Печать" action="#{StorekeeperOrderBean.orderPrint}" onclick="window.open('skprint')" style="font-size: 1.1em;"/>
        </h:form>
        <h:outputText value=" "/>
        <h:outputText value="Номер ИС" style="font-weight:bold"/>
        <h:outputText value="#{StorekeeperOrderBean.order.id}"/>
        <h:outputText value="Счет 1С" style="font-weight:bold"/>
        <h:outputText value="#{StorekeeperOrderBean.order.c1Num}"/>
        <h:outputText value="Дата создания" style="font-weight:bold"/>
        <h:outputText value="#{StorekeeperOrderBean.order.creationDateAsString}"/>
        <h:outputText value="Менеджер" style="font-weight:bold"/>
        <h:outputText value="#{StorekeeperOrderBean.order.manager.fio}"/>
        <h:outputText value="Клиент" style="font-weight:bold"/>
        <h:outputText value="#{StorekeeperOrderBean.order.client.companyName}"/>
        <h:outputText value="Комментарий для водителей" style="font-weight:bold"/>
        <h:outputText value="#{StorekeeperOrderBean.order1CString}"/>
        <h:outputText value="Комментарий для склада" style="font-weight: bold"/>
        <h:outputText value="#{StorekeeperOrderBean.order1CStringForStorekeeper}"/>
    </h:panelGrid>

    <rich:separator/>

    <h:form>
        <h:panelGroup layout="block" styleClass="" style="padding:5px">
            <jsp:include page="messages.jsp"/>
            <rich:dataTable value="#{StorekeeperOrderBean.orderItems}"
                            var="orderItem"
                            rowKeyVar="row">
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="№"/>
                    </f:facet>
                    <h:outputText value="#{row + 1}. "/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Код"/>
                    </f:facet>
                    <h:outputText value="#{orderItem.good.code}" styleClass="b"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Наименование"/>
                    </f:facet>
                    <h:outputText value="#{orderItem.good.name}" styleClass="b"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Количество" style="font-weight:bold"/>
                    </f:facet>
                    <h:outputText value="#{orderItem.count} шт." rendered="#{StorekeeperOrderBean.isBuildMode}"/>
                    <h:outputText value="#{orderItem.factGivenFromStore} шт."
                                  rendered="#{StorekeeperOrderBean.isOutMode}"/>
                </rich:column>

                <rich:column rendered="#{StorekeeperOrderBean.isBuildMode}">
                    <f:facet name="header">
                        <h:outputText value="Выдано" style="font-weight:bold"/>
                    </f:facet>
                    <h:inputText value="#{StorekeeperOrderBean.factGivenMap[orderItem.id]}"
                                 required="true"
                                 requiredMessage="Поле \"Выдано\" должно быть заполнено для товара #{orderItem.good.code}"
                                 style="width:35px"/>
                </rich:column>

                <rich:column rendered="#{StorekeeperOrderBean.isBuildMode}"
                             width="10"
                             headerClass="preformatted">
                    <f:facet name="header">
                        <h:outputText value="Изм. по указанию менеджера"/>
                    </f:facet>
                    <h:selectBooleanCheckbox value="#{orderItem.changedByManager}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="№ Гр.тары"/>
                    </f:facet>
                    <h:inputText value="#{orderItem.packageNumber}"
                                 readonly="#{StorekeeperOrderBean.isOutMode}"
                                 required="false"
                                 requiredMessage="Поле \"№ Гр. тары\" должно быть заполнено для товара #{orderItem.good.code}"
                                 style="width:35px"
                            converterMessage="Поле \"№ Гр. тары\" должно быть числом">
                        <f:convertNumber integerOnly="true" type="number" />
                            </h:inputText>


                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Свободный остаток" style="font-weight:bold"/>
                    </f:facet>
                    <h:outputText value="#{orderItem.good.count} шт."/>
                </rich:column>
            </rich:dataTable>
        </h:panelGroup>
    <h:panelGroup layout="block" style="padding: 5px; text-align: left" >
        <h:outputText value="Ответственный за сборку заказа: "/>
        <h:selectOneMenu value="#{StorekeeperOrderBean.order.storekeeperId}" styleClass="f_s"
                         style="width:200px" disabled="#{StorekeeperOrderBean.isOutMode}">
            <f:selectItems value="#{StorekeeperOrderBean.storeKeepers}"/>
        </h:selectOneMenu>
    </h:panelGroup>


        <h:panelGroup layout="block" styleClass="" style="padding:5px">
            <a4j:commandButton value="Готово"
                               action="#{StorekeeperOrderBean.commit}"
                               style="width:150px;font-weight:bold"/>
            <a4j:commandButton value="Отмена"
                               action="#{StorekeeperOrderBean.cancel}"
                               style="width:150px;font-weight:normal;margin-left:10px"/>
        </h:panelGroup>
    </h:form>
</f:view>
</body>
</html>